package com.ete.service.service.version.sp

import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.TimeUtils
import com.ete.service.manager.log.LogManager
import com.ete.service.util.log.EteLog

/**
 * Author:LiXian
 * <p>
 * Desc:TODO
 * Version:1.0
 * date 2023/12/28 10:24
 */
object VersionSpUtil {

    private val DATE_FORMAT = TimeUtils.getSafeDateFormat("yyyy-MM-dd")

    @JvmStatic
    fun isNoticeUpgrade(version: String): Boolean {
        val notNoticeVersion = getNotNoticeVersion()
        EteLog.d(LogManager.TAG, "获取上次不再提醒的版本notNoticeVersion:[$notNoticeVersion]，当前版本version:[$version]")
        if (notNoticeVersion != version) {
            val noticeDate = SPUtils.getInstance().getString("DATE_NOTICE_UPGRADE", "")
            val nowDate = TimeUtils.getNowString(DATE_FORMAT)
            EteLog.d(LogManager.TAG, "获取上次提醒升级的时间noticeDate:[$noticeDate]，当前时间nowDate:[$nowDate]")
            return noticeDate != nowDate
        }
        return false
    }

    @JvmStatic
    fun putNoticeUpgradeDate() {
        val nowDate = TimeUtils.getNowString(DATE_FORMAT)
        SPUtils.getInstance().put("DATE_NOTICE_UPGRADE", nowDate)
    }

    @JvmStatic
    private fun getNotNoticeVersion(): String {
        val notNoticeVersion = SPUtils.getInstance().getString("VERSION_NOT_NOTICE", "")
        EteLog.d(LogManager.TAG, "获取不再提醒升级的版本version:[$notNoticeVersion]")
        return notNoticeVersion
    }

    @JvmStatic
    fun putNotNoticeVersion(version: String) {
        EteLog.d(LogManager.TAG, "保存不再提醒升级的版本version:[$version]")
        SPUtils.getInstance().put("VERSION_NOT_NOTICE", version)
    }
}